#include <string>
#include "Matrix.hpp"

using namespace std;
using namespace YMatrix;

void WelcomeMsg();

int main(int argc, char* argv[])
{
	WelcomeMsg();

	// typedef for normal mathematical matrix with double as datatype.
	typedef Matrix<double,DenseMatrix,MathMatrix> MatrixM;

	bool canQuit = false; string shouldQuit = "";
	
	// prepare a 5 x 5 array
	//double a1[25] = {1,1,1,1,1, 2,2,2,2,2, 3,3,3,3,3, 2,2,2,2,2, 1,1,1,1,1};
	double a1[49] = 
	{
		1,		0,		0,		0,		0,		0,		0, 
		0.67,	0,		0.33,	0,		0,		0,		0, 
		0,		0.67,	0,		0.33,	0,		0,		0,
		0,		0,		0.67,	0,		0.33,	0,		0,
		0,		0,		0,		0.67,	0,		0.33,	0,
		0,		0,		0,		0,		0.67,	0,		0.33,
		0,		0,		0,		0,		0,		0,		1
	};

	// construct a 5 x 5 matrix with no initial value
	//MatrixM mathMatrix1(5,5);
	MatrixM mathMatrix1(7,7);

	// fill matrices with array
	mathMatrix1 = a1;

	cout << "Matrix M:\n" << mathMatrix1;

	// construct a second 5 x 5 matrix to store powers of mathMatrix1
	//MatrixM mathMatrix2(5,5);
	MatrixM mathMatrix2(7,7);
	double a2[49] = {1,0,0,0,0,0,0, 0,1,0,0,0,0,0, 0,0,1,0,0,0,0, 0,0,0,1,0,0,0, 0,0,0,0,1,0,0, 0,0,0,0,0,1,0, 0,0,0,0,0,0,1};
	mathMatrix2 = a2;
	
	int input_1, input_2, input_3;

	//mathMatrix2 = mathMatrix1;
	do
	{
		cout << "What is the probability that the game currently in state 'x' is in state 'y' after 'n' more moves? Enter three integers x, y, n (1<=x<=7, 1<=y<=7, seperated by spaces): ";
		cin >> input_1 >> input_2 >> input_3;

		for (int i=0; i< input_3; ++i )
		{
			mathMatrix2 *= mathMatrix1;
		}

		//mathMatrix2 = mathMatrix1 * mathMatrix1 * mathMatrix1 * mathMatrix1 ;

		cout << "\nMatrix M^" << input_3 << ":\n" << mathMatrix2;

		// row counter and column counter start at row 0 and column 0
		// so subtract 1 from the row and column wanted
		//cout << "The value at row 4 column 5 of Matrix M Squared is: "<< mathMatrix2.at(3,4) << endl;
		cout << "\nThe probability that the game currently in state " << input_1 << " is in state "
			<< input_2 << " after " << input_3 << " more moves is: " << mathMatrix2.at(input_1 -1,input_2 -1) << endl;


		//char temp;
		//cout << "Press any key and enter to quit." << endl;
		//cin >> temp;
		cout << "\nQuit Program Y/N ? ";  cin >> shouldQuit;
		canQuit = (shouldQuit == "Y" || shouldQuit == "y") ? true : false;
		if (canQuit) cout << "\nThank you - Good Bye!\n" << endl;
	}
	while ( !canQuit);

	return 0;
}


void WelcomeMsg()
{
    cout << endl;
    cout << "===================================================" << endl;
    cout << "Welcome to the Matrices and Markov Chains Program" << endl;
    cout << "Class Assignment: MATH 233 - iLab 4" << endl;
    cout << "Author: Ronald Ram" << endl;
    cout << "===================================================" << endl << endl;
}